#include <iostream>
#include <queue> 
#define endl "\n" 
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	queue<int> q; 
	int n,op,data;
	cin>>n;
	while(n--)
	{
		cin>>op;
		if (op==1)
		{
			cin>>data;
			q.push(data);				
		}	
		else if (op==2)
		{
			if (q.empty())
				cout<<"ERR_CANNOT_POP"<<endl;
			else
				q.pop();
		}
		else if (op==3)
		if (q.empty())
				cout<<"ERR_CANNOT_QUERY"<<endl;
		else
				cout<<q.front()<<endl;
		else
			cout<<q.size()<<endl;
	} 
}
